#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int numberOfArithmeticSlices(vector<int>& nums) {
        int n = nums.size(), ret = 0;
        unordered_map<long long, vector<int>> hash1;
        hash1[nums[0]].push_back(0);
        vector<vector<int>> dp(n, vector<int>(n));
        for (int i = 1; i < n; i++)
        {
            for (int j = i + 1; j < n; j++)
            {
                long long a = nums[i] - ((long long)nums[j] - nums[i]);
                if (hash1.count(a))
                    for (auto y : hash1[a]) dp[j][i] += dp[i][y] + 1;
                ret += dp[j][i];
            }
            hash1[nums[i]].push_back(i);
        }
        return ret;
    }
};